<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<import type="js" file="js.jquery" />
<import type="js" file="js.My97DatePicker.WdatePicker" />
<import type="js" file="js.common" />
<import type="css" file="css.global" />
<import type="css" file="css.form" />
</head>
<body>
<div id="form">
	<form name="form1" action="__APP__/WorkLog/monthly_insert" method="post" onsubmit="return CheckForm();" >
	<table class="TableBlock">
		<tr>
			<td>月度工作计划</td>
			<td>权重比列</td>
			<td>计划完成时间<if condition="$vo['status'] eq 0">&nbsp;&nbsp;&nbsp;<input type="button" value="新增一列" id="button" class="button"></if></td>
		</tr>
		<if condition="$count eq 0">
		<tr style="height:50px;" class=tr_list id='1'>
			<td><textarea cols="40" name="log_text[]" rows="2" wrap="on" id="log_text" style="height: 40px;">{$vo.log_text}</textarea></td>
			<td><input type="text" name="weight[]" size="10" class="weight" value="{$vo.weight}" />%</td>
			<td><input type="text" class="Wdate" name="over_time[]" name="over_time[]" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" /></td>
		</tr>
		<else />
		<volist name="list" id="vo" item="key" >
		<tr style="height:50px;" class=tr_list id='{$key+1}'>
			<td><textarea cols="40" name="log_text[]" rows="2" wrap="on" id="log_text" style="height: 40px;">{$vo.log_text}</textarea></td>
			<td><input type="text" name="weight[]" size="10" value="{$vo.weight}" />%</td>
			<td><input type="text" class="Wdate" name="over_time[]" name="over_time[]" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" /><if condition="$key neq 0" ><input type=button value=' - '  title=删除目标 onclick=shanchu({$key+1})></if></td>
		</tr>
		</volist>
		</if>
	</table>
	<table>
		<tr>
			<td>
		</br><strong>其他问题与建议（请提出与本职工作有关的现存的问题与改进方法）</strong></br></br>
        <textarea cols="80" name="log_question" rows="5" >{$vo.log_question}</textarea></br></td>
		</tr>
		<tr>
			<td><input type="hidden" name="log_id" value="{$vo.log_id}">
		      	<input type="hidden" name="flag" id="flag" value="0">
		     	<if condition="$vo['status'] eq 0">
				<input type="submit" value="保存" class="submit" id="submit" >&nbsp;&nbsp;
				<input type="submit" value="提交" class="submit" id="setmap" >&nbsp;&nbsp;
				</if>
				<input type="button" value="返回" class="button" onclick="back()">
			</td>
		</tr>
	</table>
	</form>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
	$("#submit").click(function(){
		$("#flag").val('0');
	});
	$("#setmap").click(function(){
		$("#flag").val('1');
		if(confirm("确定提交么？日志提交之后无法修改！")){
			
		}else{
			return false;
		}
	});
	$("#button").click(function (){
		var x = $(".tr_list").size();
		var table = "<tr class=tr_list id='"+(x+1)+"' style=\"height:50px;\"> <td>  <textarea cols=40 name=log_text[] rows=2 style=\"height:40px;\" wrap=on id=log_text ></textarea></td><td><input type=text name=weight[] class=weight size=10 />%</td><td><input type=text class=Wdate name=over_time[] onClick=WdatePicker({dateFmt:'yyyy-MM-dd'}) /><input type=button value=' - '  title=删除目标 onclick=shanchu("+(x+1)+")></td></tr>";
		$(".TableBlock").append(table);
	});
});

function shanchu(i){
	$("#"+i).remove();
}

function CheckForm(){
	var x = $(".tr_list").size();
	var weight_sum = 0;
	for(var i=1; i<(x+1); i++){
		$("#"+i+" textarea").each(function(){
			if($(this).text() == ''){
				alert("第"+i+"行的工作计划不能为空！"); return false;
			}
		});
		
		var weight = $("#"+i+" .weight").val();
		alert(weight);
		if( parseInt(weight)!=weight || weight<=0 || weight > 100 ){
			alert("第"+i+"行的权重比例数值非法，请填写不大于100的正整数！");return false;
		}
		weight_sum = parseInt(weight_sum)+parseInt(weight);
		var over_time = $("#"+i+" .Wdate").val();
		if( over_time== ''){
			alert("第"+i+"行计划完成时间不能为空！");return false;
		}else{
			var time = parseInt(over_time.replace(/-/g, ""));
			var date = new Date();
			var month = date.getMonth()+1;
			var dat = date.getDate();
			
			if(month < 10){
				month = "0"+month;
			}
			if( dat < 10 ){
				dat = "0"+dat;
			}
			var today = date.getFullYear()+''+month+''+dat;
			if( time<= today){
				alert("第"+i+"行计划完成时间必须要大于当前时间！");return false;
			}
		}
	}
	if( parseInt(weight_sum) != 100 ){
		alert("工作目标权重比例设置错误，总权重必须为100！");return false;
	}
}
</script>
</html>